
** Figure H.9: Remove states at a time

use "$datadir\ewallet\maindata.dta", clear
	levelsof state, local(s)

	g exposureXpost = invshare_sd*post
	
	foreach i in `s'{
		di "`i'"
		qui statsby eff=_b[exposureXpost]  se =_se[exposureXpost]  , saving("$datadir\coeff_states`i'.dta", replace): reghdfe  logamount exposureXpost if !inlist(state,"`i'") & $filters, a($fe $controls##i.time_id) cluster(district_id)	
	}
	
	use "$datadir\ewallet\maindata.dta", clear
	levelsof state, local(s)
	foreach i in `s'{
		use "$datadir\coeff_states`i'.dta" , clear
		g state = "`i'"
		save "$datadir\coeff_states`i'.dta", replace
	}
	
	
	clear 
	g blankvar = . 
	save "$datadir\coeff_states.dta" , replace
	use "$datadir\ewallet\maindata.dta", clear
	levelsof state, local(s)	
	use "$datadir\coeff_states.dta" , clear
	foreach i in `s'{
		append using "$datadir\coeff_states`i'.dta"
		erase "$datadir\coeff_states`i'.dta"
	}
	egen stateid = group(state)
save "$datadir\coeff_states.dta", replace


*** Final graph
use "$datadir\coeff_states.dta" , clear
	drop if mi(state)
	drop blankvar

		
		  tset stateid
		  gen t_10=1.65
		  gen t_5=1.96
		 
		  foreach num in 5 10 {
		  gen low_bound_`num'=eff-(t_`num'*se)
		  gen up_bound_`num'=eff+(t_`num'*se)
		 }
		 
		 g insignificant10 = (up_bound_10 >= 0 & low_bound_10 <=0)
		 g insignificant5 = (up_bound_5 >= 0 & low_bound_5 <=0)
		 replace insignificant5 = 1 if insignificant10 == 1
		 drop if stateid > 21
		
		twoway (rcap up_bound_10 low_bound_10 stateid, lcolor(gray) lstyle(ci)) ///
		(scatter eff stateid if insignificant10 == 1, lcolor(black) mcolor(gray) msymbol(circle_hollow) msize(medlarge)) (scatter eff stateid if insignificant10 == 0, lcolor(black) mcolor(black) msymbol(circle) msize(medium)) , ///
		legend(off) graphregion(color(white))  ylabel(,nogrid) ylab(0.5(1)6)  yline(3.134, lcolor(black) lpattern(dash))  ///
		xtitle("State excluded from sample") ytitle("Effect on amount transacted") ///
		xlabel(1 "ANDHRA PRADESH" 2 "ASSAM" 3 "BIHAR" 4 "CHHATTISGARH" 5 "GOA" 6 "GUJARAT" 7 "HARYANA" 8 "HIMACHAL PRADESH" 9 "JAMMU&KASHMIR" 10 "JHARKHAND" 11 "KARNATAKA" 12 "KERALA" 13 "MADHYA PRADESH" 14 "MAHARASHTRA" 15 "ORISSA" 16 "PUNJAB" 17 "RAJASTHAN" 18 "TAMIL NADU" 19 "UTTAR PRADESH" 20 "UTTARAKHAND" 21 "WEST BENGAL", angle(vertical) tstyle(major_notick) labsize(vsmall))
		
		
		graph export "$outputdir_fig\Figure_H_9.pdf", as(pdf) replace
		erase "$datadir\coeff_states.dta"
		
